package com.ruoyi.youtian.controller;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.youtian.domain.FaultNotifyAnnounceUser;
import com.ruoyi.youtian.service.IFaultNotifyAnnounceUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报警公告消息阅读记录Controller
 * 
 * @author ruoyi
 * @date 2022-12-08
 */
@Controller
@RequestMapping("/announceReadRecord/announceReadRecord")
public class FaultNotifyAnnounceUserController extends BaseController
{
    private String prefix = "announceReadRecord/announceReadRecord";

    @Autowired
    private IFaultNotifyAnnounceUserService faultNotifyAnnounceUserService;

    @RequiresPermissions("announceReadRecord:announceReadRecord:view")
    @GetMapping()
    public String announceReadRecord()
    {
        return prefix + "/announceReadRecord";
    }

    /**
     * 查询报警公告消息阅读记录列表
     */
    @RequiresPermissions("announceReadRecord:announceReadRecord:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FaultNotifyAnnounceUser faultNotifyAnnounceUser)
    {
        startPage();
        List<FaultNotifyAnnounceUser> list = faultNotifyAnnounceUserService.selectFaultNotifyAnnounceUserList(faultNotifyAnnounceUser);
        return getDataTable(list);
    }

    /**
     * 导出报警公告消息阅读记录列表
     */
    @RequiresPermissions("announceReadRecord:announceReadRecord:export")
    @Log(title = "报警公告消息阅读记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FaultNotifyAnnounceUser faultNotifyAnnounceUser)
    {
        List<FaultNotifyAnnounceUser> list = faultNotifyAnnounceUserService.selectFaultNotifyAnnounceUserList(faultNotifyAnnounceUser);
        ExcelUtil<FaultNotifyAnnounceUser> util = new ExcelUtil<FaultNotifyAnnounceUser>(FaultNotifyAnnounceUser.class);
        return util.exportExcel(list, "报警公告消息阅读记录数据");
    }

    /**
     * 新增报警公告消息阅读记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存报警公告消息阅读记录
     */
    @RequiresPermissions("announceReadRecord:announceReadRecord:add")
    @Log(title = "报警公告消息阅读记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FaultNotifyAnnounceUser faultNotifyAnnounceUser)
    {
        faultNotifyAnnounceUser.setRecipientUserId(getUserId());
        faultNotifyAnnounceUser.setCreateTime(DateUtils.getNowDate());
        return toAjax(faultNotifyAnnounceUserService.insertFaultNotifyAnnounceUser(faultNotifyAnnounceUser));
    }

    /**
     * 修改报警公告消息阅读记录
     */
    @RequiresPermissions("announceReadRecord:announceReadRecord:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        FaultNotifyAnnounceUser faultNotifyAnnounceUser = faultNotifyAnnounceUserService.selectFaultNotifyAnnounceUserById(id);
        mmap.put("faultNotifyAnnounceUser", faultNotifyAnnounceUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存报警公告消息阅读记录
     */
    @RequiresPermissions("announceReadRecord:announceReadRecord:edit")
    @Log(title = "报警公告消息阅读记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FaultNotifyAnnounceUser faultNotifyAnnounceUser)
    {
        return toAjax(faultNotifyAnnounceUserService.updateFaultNotifyAnnounceUser(faultNotifyAnnounceUser));
    }


    /**
     * 修改阅读状态 0未读 1已读
     */
    @RequiresPermissions("announceReadRecord:announceReadRecord:edit")
    @Log(title = "报警公告消息阅读记录", businessType = BusinessType.UPDATE)
    @PostMapping("/update")
    @ResponseBody
    public AjaxResult updateSave(FaultNotifyAnnounceUser faultNotifyAnnounceUser)
    {
        faultNotifyAnnounceUser.setRecipientUserId(getUserId());
        return toAjax(faultNotifyAnnounceUserService.updateFaultNotifyAnnounceReadStatus(faultNotifyAnnounceUser));
    }

    /**
     * 删除报警公告消息阅读记录
     */
    @RequiresPermissions("announceReadRecord:announceReadRecord:remove")
    @Log(title = "报警公告消息阅读记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(faultNotifyAnnounceUserService.deleteFaultNotifyAnnounceUserByIds(ids));
    }
}
